<template>
    <view class="container">
        <!-- 拍照按钮 -->
        <button class="btn" type="primary" @click="takePhoto">拍照</button>
        
        <!-- 图片裁剪组件 -->
        <view class="crop-container" v-if="showCrop">
            <image :src="tempPhotoPath" class="crop-image"></image>
            <view class="crop-mask top"></view>
            <view class="crop-mask bottom"></view>
            <view class="crop-box"></view>
            <button class="btn" type="default" @click="confirmCrop">确认裁剪</button>
            <button class="btn" type="default" @click="cancelCrop">取消裁剪</button>
        </view>
        
        <!-- 图片显示区域 -->
        <view class="image-display" v-if="processedImage">
            <image :src="processedImage" mode="aspectFit"></image>
        </view>
        
        <!-- 保存的图片列表 -->
        <view class="saved-images">
            <view class="saved-image-item" v-for="(item, index) in savedImages" :key="index">
                <image :src="item.path" mode="aspectFit"></image>
                <view class="image-info">
                    <text>文件名: {{ item.name }}</text>
                    <text>大小: {{ item.size }} KB</text>
                    <text>时间: {{ item.time }}</text>
                </view>
            </view>
        </view>
    </view>
</template>

<style scoped>
.container {
    padding: 20px;
    background-color: #f5f5f5;
    min-height: 100vh;
}

.btn {
    margin-bottom: 20px;
}

.crop-container {
    position: relative;
    width: 100%;
    height: 300px;
    background-color: #000;
    margin-bottom: 20px;
}

.crop-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.crop-mask {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
}

.crop-mask.top {
    width: 100%;
    height: 30%;
    top: 0;
}

.crop-mask.bottom {
    width: 100%;
    height: 30%;
    bottom: 0;
}

.crop-box {
    position: absolute;
    width: 60%;
    height: 40%;
    left: 20%;
    top: 30%;
    border: 1px solid #fff;
    box-sizing: border-box;
}

.image-display {
    width: 100%;
    height: 300px;
    margin-bottom: 20px;
}

.image-display image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.saved-images {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
}

.saved-image-item {
    width: 48%;
    margin-bottom: 15px;
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.saved-image-item image {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.image-info {
    padding: 8px;
    font-size: 12px;
    color: #666;
}
</style>

<script src='./mi.js'></script>